﻿<%@ Page Language="C#" MasterPageFile="~/Common/Master/PopupDiv.master" AutoEventWireup="true" Inherits="Project_Task_Edit" Title="无标题页" Codebehind="Edit.aspx.cs" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <style type="text/css">
         .style1
        {
             width:100px; padding-right:10px; text-align:right; padding-top:2px; padding-bottom:2px;
        }
        .style2
        {
             text-align:left;  padding-top:2px; padding-bottom:2px;
        }
        
    </style>
    
    <script type="text/javascript">
        
        
        function setTimeLimit()
        {
            window.setTimeout(setDays,100);
            
        }
        
        function setDays()
        {
            var txtStartTime = document.getElementById("<%= StartTime.ClientID %>");
            var txtEndTime = document.getElementById("<%= EndTime.ClientID %>"); 
            var txtTimeLimit = document.getElementById("<%= TimeLimit.ClientID %>"); 
            
            if(txtStartTime.value == "" || txtEndTime.value == "")
            {
                return;
            }
            
            var startTime = GetDateTime(txtStartTime.value);        
            var endTime = GetDateTime(txtEndTime.value);
            
            
            var msSpan = endTime.getTime() - startTime.getTime();

            var days = msSpan / (24 * 60 * 60 * 1000);

            if (days > 0)
            {
                var chkWeekend = document.getElementById("chkWeekend");

                if (chkWeekend.checked == true)
                {
                    var restDays = parseInt(days / 7 * 2); //双休天数

                    if (days % 7 > 0)
                    {
                        var startDay = startTime.getDay();
                        var endDay = endTime.getDay();

                        if (startDay > endDay)
                        {
                            if (startDay == 6 ^ endDay == 0)//开始和结束有一天是双休天
                            {
                                restDays += 1;
                            }
                            else if (startDay != 6 && endDay != 0)
                            {
                                restDays += 2;
                            }
                        }
                        else
                        {
                            if (startDay == 0 && endDay == 6)
                            {
                                restDays += 2;
                            }
                            else if (startDay == 0 || endDay == 6)
                            {
                                restDays += 1;
                            }
                        }
                    }

                    days -= restDays;

                    days = (days < 0) ? 0 : days;
                }
            }
            else
            {
                days = 0;
            }
            txtTimeLimit.value = days;
        }
        
        function GetDateTime(strDateTime)
        {
            var strDate = strDateTime.split(" ")[0];
            var strTime = strDateTime.split(" ")[1];       
            
            var dates = strDate.split("-");
            var times = null;
            if(strTime != null)
            {
                times = strTime.split(":");
            }

            dates[1] = parseInt(dates[1]) - 1;
           
            var date;
            
            if(times != null)
            {
                date = new Date(dates[0],dates[1],dates[2],times[0],times[1],times[2]);
            }
            else
            {
                date = new Date(dates[0],dates[1],dates[2]);
            }
            return date;
        }
        function CheckPercent(source, args)
        {
            var value = parseInt(args.Value);
            if(value < 0 || value > 100)
            {
                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }

        function chkCalendar_Click(src, lbl, drp)
        {
            lbl = document.getElementById(lbl);
            drp = document.getElementById(drp);
            if (src.checked)
            {
                lbl.style.display = "";
                drp.style.display = "";
            }
            else
            {
                lbl.style.display = "none";
                drp.style.display = "none";
            }
        }
    </script>
    <script type="text/javascript" src="../../Common/Js/calendar.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:Panel ID="pnlMain" runat="server" CssClass="pnlMain">
        <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;" class="tbl1">
            <tr>
                <td class="style1">
                    <span style="color:Red">*</span>&nbsp;<asp:Label ID="Label1" runat="server" Text="任务名称："></asp:Label></td>
                <td class="style2">
                    <asp:TextBox ID="Name" runat="server" Width="245px" CssClass="txt"></asp:TextBox><asp:HiddenField
                        ID="UpperID" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="Name" Display="None" ErrorMessage="请输入任务名称" 
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
                </td>
            </tr>
             <tr>
                <td class="style1">
                    <span style="color:Red">*</span>&nbsp;<asp:Label ID="Label2" runat="server" Text="计划起止日期："></asp:Label></td>
                <td class="style2">
                    <asp:TextBox ID="StartTime" runat="server" Width="75px" CssClass="txt"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                        ControlToValidate="StartTime" Display="None" ErrorMessage="请选择计划开始日期"></asp:RequiredFieldValidator>
                    至 
                    <asp:TextBox ID="EndTime" runat="server" Width="75px" CssClass="txt"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                        ControlToValidate="EndTime" Display="None" ErrorMessage="请选择计划结束日期"></asp:RequiredFieldValidator>
                    <asp:CheckBox ID="IsPrediction" runat="server" Text="预估" />
                 </td>
            </tr>
             <tr>
                <td class="style1">
                    <span style="color:Red">*</span>&nbsp;<asp:Label ID="Label3" runat="server" Text="工期："></asp:Label></td>
                <td class="style2">
                    <asp:TextBox ID="TimeLimit" runat="server" Width="25px" CssClass="txt"></asp:TextBox>(工作日)
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TimeLimit" Display="None" ErrorMessage="工期应为整数 " 
                        SetFocusOnError="True" ValidationExpression="\d+"></asp:RegularExpressionValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                        ControlToValidate="TimeLimit" Display="None" ErrorMessage="请填写工期" 
                        SetFocusOnError="True"></asp:RequiredFieldValidator>
                        <input id="chkWeekend" type="checkbox" checked="checked" onclick="setDays()" /><label for="chkWeekend">不计双休</label>
                    <asp:CheckBox ID="IsMilestone" runat="server" Text="标记为里程碑" />
                 </td>
            </tr>
            
             <tr>
                <td class="style1">
                    <span style="color:Red">*</span>&nbsp;<asp:Label ID="Label5" runat="server" Text="执行人员："></asp:Label></td>
                <td class="style2">
                    <asp:TextBox ID="UserNames" runat="server" Height="50px" TextMode="MultiLine"  CssClass="txt"
                        Width="250px" ToolTip="单击选择执行人员"></asp:TextBox>
                        <asp:HiddenField ID="UserIDs" runat="server" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="UserNames" Display="None" ErrorMessage="请选择执行人员"></asp:RequiredFieldValidator>
                </td>
            </tr>
             <tr>
                <td class="style1">
                    <asp:Label ID="Label6" runat="server" Text="任务描述："></asp:Label></td>
                <td class="style2">
                    <asp:TextBox ID="Remark" runat="server" Height="50px" TextMode="MultiLine"  CssClass="txt"
                        Width="250px"></asp:TextBox>
                    <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
                        ShowMessageBox="True" ShowSummary="False" />
                 </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:Label ID="Label4" runat="server" Text="关联日程："></asp:Label></td>
                <td class="style2">
                    <asp:CheckBox ID="chkCalendar" runat="server" Text="是" 
                        style="margin-right:10px" TextAlign="Right" /><asp:Label ID="lblCalendarTypeID" runat="server"
                            Text="日程类型：" style="display:none;"></asp:Label><asp:DropDownList ID="drpCalendarTypeID" style="display:none;"
                        runat="server">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr id="trReason" runat="server" visible="false">
                <td class="style1"><asp:Label ID="Label7" runat="server" Text="变更原因：" ForeColor="Red"></asp:Label></td>                
                <td class="style2"><asp:TextBox ID="txtReason" runat="server" Height="41px" TextMode="MultiLine"  CssClass="txt"
                        Width="250px"></asp:TextBox>                   
                </td>
            </tr>
        </table>
    </asp:Panel>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="Server">
    <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" Text="保存" />
</asp:Content>
